package com.Imp;

import com.entity.Customer;
import com.entity.Deliveryman;
import com.mapper.DeliverymanMapper;
import com.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.HashMap;
import java.util.Map;

public class DeliverymanMapperImpl implements DeliverymanMapper {

    public Deliveryman getDeliverymanByUserName(String userName) {
        try (SqlSession sqlSession = MyBatisUtil.openSqlSession()) {
            Map<String, Object> param = new HashMap<>();
            param.put("userName", userName);
            return sqlSession.selectOne("com.mapper.DeliverymanMapper.getDeliverymanByUserName", userName);
        }
    }

    public void addDeliveryman(Deliveryman deliveryman) {
        try (SqlSession sqlSession = MyBatisUtil.openSqlSession()) {
            sqlSession.insert("com.mapper.DeliverymanMapper.addDeliveryman", deliveryman);
            sqlSession.commit();
        }
    }

    public void updateDeliveryman(Deliveryman deliveryman) {
        try (SqlSession sqlSession = MyBatisUtil.openSqlSession()) {
            sqlSession.update("com.mapper.DeliverymanMapper.updateDeliveryman", deliveryman);
            sqlSession.commit();
        }
    }

    public void deleteDeliveryman(String userName) {
        try (SqlSession sqlSession = MyBatisUtil.openSqlSession()) {
            sqlSession.delete("com.mapper.DeliverymanMapper.deleteDeliveryman", userName);
            sqlSession.commit();
        }
    }
}
